/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 * */

// AmzServer - Tototoy's server model.
// Author: tonyjobmails@gmail.com (tonyhack).
//
// Define class UDPSocketCommunicator.
//
// UDPSocketCommunicator uses to send/receive UDP messages.
//

#ifndef __UDP__SOCKET__COMMUNICATOR__H
#define __UDP__SOCKET__COMMUNICATOR__H

#include "udp_socket.h"

namespace amz {

class UDPSocketCommunicator {
 public:
  UDPSocketCommunicator(const sockaddr_in &address, int len,
         UDPSocket *udp_socket, int flag = 0);
  virtual ~UDPSocketCommunicator();

  // Set destination of address.
  // return 0 sucess.
  // return -1 is an error value.
  int SetDestinationAddress(const sockaddr_in *addr, int len);

  // Send.
  // Packet pattern: send to socket.
  // Stream pattern: send to buffer.
  virtual int Send(const char *message, int size) = 0;

  // Receive.
  // Packet pattern: Receive from socket.
  // Stream pattern: Receive from buffer.
  virtual int Receive(char *message, int max_size) = 0;

 protected:
  struct sockaddr_in address_in4_;

  // udp socket pointer.
  UDPSocket *udp_socket_;

  int flag_;
};

}  // namespace amz

#endif  // __UDP__SOCKET__COMMUNICATOR__H
